package com.softer.wxzj.controller;

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.entity.BaseBuildInfo;
import com.softer.wxzj.entity.BaseRegionInfo;
import com.softer.wxzj.entity.MaintenanceEquipment;
import com.softer.wxzj.entity.TempEquipment;
import com.softer.wxzj.service.MaintenanceEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 维修设备
 *
 * @author Gong Zhiyang
 * @date 2019/7/16
 */
@RestController
@RequestMapping("/maintenanceEquipment")
public class MaintenanceEquipmentController {
    @Autowired
    private MaintenanceEquipmentService maintenanceEquipmentService;

    /**
     * 新增维修设备
     *
     * @param maintenanceEquipment 维修设备
     * @return 新增结果
     */
    @PostMapping("/add")
    public CommonResult add(@RequestBody MaintenanceEquipment maintenanceEquipment) {
        return maintenanceEquipmentService.add(maintenanceEquipment);
    }

    /**
     * 修改维修设备
     *
     * @param maintenanceEquipment 维修设备
     * @return 修改结果
     */
    @PostMapping("/update")
    public CommonResult update(@RequestBody MaintenanceEquipment maintenanceEquipment) {
        return maintenanceEquipmentService.update(maintenanceEquipment);
    }

    /**
     * 查询详情
     *
     * @param id      ID
     * @param arcType 图档大类
     * @return 维修设备详情
     */
    @PostMapping("/getInfo")
    public MaintenanceEquipment getInfo(String id, String arcType) {
        return maintenanceEquipmentService.getInfo(id, arcType);
    }

    /**
     * 查刪除维修设备
     *
     * @param id ID
     * @return 删除结果
     */
    @PostMapping("/delete")
    public CommonResult delete(String id) {
        return maintenanceEquipmentService.delete(id);
    }

    /**
     * 竣工
     *
     * @param id   自然幢ID
     * @param date 竣工日期
     * @return 操作结果
     */
    @PostMapping("/finish")
    public CommonResult finish(String id, String date) {
        return maintenanceEquipmentService.finish(id, date);
    }

    /**
     * 维修对象维护列表
     *
     * @param page           分页实体
     * @param baseRegionInfo 查询实体
     * @return 小区列表
     */
    @PostMapping("/getRegionList")
    public PageInfo<BaseRegionInfo> getRegionList(Page page, BaseRegionInfo baseRegionInfo) {
        return maintenanceEquipmentService.getRegionList(page, baseRegionInfo);
    }

    /**
     * 根据小区ID查询自然幢列表
     *
     * @param page          分页实体
     * @param baseBuildInfo 查询实体
     * @return 自然幢列表
     */
    @PostMapping("/getBuildList")
    public PageInfo<BaseBuildInfo> getBuildList(Page page, BaseBuildInfo baseBuildInfo) {
        return maintenanceEquipmentService.getBuildList(page, baseBuildInfo);
    }

    /**
     * 根据小区ID或者自然幢ID查询公共设施
     *
     * @param page          分页实体
     * @param tempEquipment 查询实体
     * @return 公共设施列表
     */
    @PostMapping("/getEquipmentList")
    public PageInfo<TempEquipment> getEquipmentList(Page page, TempEquipment tempEquipment) {
        return maintenanceEquipmentService.getEquipmentList(page, tempEquipment);
    }

    /**
     * 外网查询查询维修对象列表
     *
     * @param page          分页实体
     * @param tempEquipment 查询实体
     * @return 维修对象列表
     */
    @PostMapping("/getEquipmentListByOperNo")
    public PageInfo<TempEquipment> getEquipmentListByOperNo(Page page, TempEquipment tempEquipment) {
        return maintenanceEquipmentService.getEquipmentListByOperNo(page, tempEquipment);
    }



    /**
     * 根据维修对象类别查询维修对象列表
     *
     * @param id 维修对象类别
     * @return 维修对象列表
     */
    @PostMapping("/getEquipmentListByObjectId")
    public List<TempEquipment> getEquipmentListByObjectId(String id) {
        return maintenanceEquipmentService.getEquipmentListByObjectId(id);
    }

    /**
     * 启用、停用维修设备
     *
     * @param maintenanceEquipment id    设备ID
     *                             state 状态（0停用，1启用）
     * @return 操作结果
     */
    @PostMapping("/enable")
    public CommonResult enable(MaintenanceEquipment maintenanceEquipment) {
        return maintenanceEquipmentService.enable( maintenanceEquipment);
    }

    /**
     * 查询详情
     *
     * @param id
     * @return
     */
    @PostMapping("/getInfoById")
    public MaintenanceEquipment getInfoById(String id) {
        return maintenanceEquipmentService.getInfoById(id);
    }

}
